<?php

class Queue {
    protected $redis;
    protected $key;

    public function __construct($args) {
        !isset($args['key']) && die('队列名称必填');
        $this->redis = new Redis();
        $this->redis->connect(REDIS_QUEUE_HOST,REDIS_QUEUE_PORT);
        $this->key = $args['key'];
    }
    
    /**
     * 获取队列长度
     *
     * @return int
     */
    public function len(){
        return $this->redis->lLen($this->key);
    }

    /**
     * 出队
     *
     * @return string
     */
    public function pop() {
        $data=$this->redis->lPop($this->key); //出
        return $data;
    }

    /**
     * 入队
     *
     * @param $tid
     * @param $seller_id
     *
     * @return bool
     */
    public function push($data) {
        $this->redis->rPush($this->key, $data);
        return true;
    }

}